/*
 *  File:             boxes.h
 *  Date created:     March 18, 1999 (Thursday, 15:09h)
 *  Author:           Copyright (C) 1999 Thomas Jensen <boxes@thomasjensen.com>
 *  Language:         ANSI C
 *  Web Site:         http://boxes.thomasjensen.com/
 *  Purpose:          Project-wide globals and data structures
 *
 *  License: o This program is free software; you can redistribute it and/or
 *             modify it under the terms of the GNU General Public License as
 *             published by the Free Software Foundation; either version 2 of
 *             the License, or (at your option) any later version.
 *           o This program is distributed in the hope that it will be useful,
 *             but WITHOUT ANY WARRANTY; without even the implied warranty of
 *             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *             GNU General Public License for more details.
 *           o You should have received a copy of the GNU General Public
 *             License along with this program; if not, write to the Free
 *             Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *             MA 02111-1307  USA
 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 */

#ifndef BOXES_H
#define BOXES_H

/* #define DEBUG */
/* #define REGEXP_DEBUG */
/* #define PARSER_DEBUG */
/* #define LEXER_DEBUG */

#include "regexp.h"



#define PROJECT "boxes"                  /* name of program */
#define VERSION "--BVERSION--"           /* current release of project */
#define GLOBALCONF "--GLOBALCONF--"      /* name of system-wide config file */


/*
 *  default settings of all kinds (THIS PARAGRAPH MAY BE EDITED)
 */
#define DEF_TABSTOP     8                /* default tab stop distance (part of -t) */
#define DEF_INDENTMODE  'b'              /* indent box, not text by default */

/*
 *  max. allowed tab stop distance
 */
#define MAX_TABSTOP     16

/*
 *  max. supported line length
 *  This is how many characters of a line will be read. Anything beyond
 *  will be discarded. The line feed character at the end does not count.
 *  (This should have been done via sysconf(), but I didn't do it in order
 *  to ease porting to non-unix platforms.)
 */
#if defined(LINE_MAX) && (LINE_MAX < 1024)
#undef LINE_MAX
#endif
#ifndef LINE_MAX
#define LINE_MAX        2048
#endif


#ifdef DEBUG
    #define __TJ(s) fprintf (stderr, s);
#else
    #define __TJ(s) /**/
#endif


#define BTOP 0                           /* for use with sides */
#define BRIG 1
#define BBOT 2
#define BLEF 3


typedef struct {
    char   *search;
    char   *repstr;
    regexp *prog;                        /* compiled search pattern */
    int     line;                        /* line of definition in config file */
    char    mode;                        /* 'g' or 'o' */
} reprule_t;


typedef struct {
    char      *name;
    char      *author;                   /* creator of the configuration file entry */
    char      *designer;                 /* creator of the original ASCII artwork */
    char      *created;                  /* date created, free format */
    char      *revision;                 /* revision number of design */
    char      *revdate;                  /* date of current revision */
    char      *sample;
    char       indentmode;               /* 'b', 't', or 'n' */
    sentry_t   shape[ANZ_SHAPES];
    size_t     maxshapeheight;           /* height of highest shape in design */
    size_t     minwidth;
    size_t     minheight;
    int        padding[ANZ_SIDES];

    reprule_t *current_rule;
    reprule_t *reprules;                 /* applied when drawing a box */
    size_t     anz_reprules;
    reprule_t *revrules;                 /* applied upon removal of a box */
    size_t     anz_revrules;
} design_t;

extern design_t *designs;
extern int anz_designs;
extern int design_idx;


extern int tjlineno;                     /* config file line counter */
extern char *yyfilename;                 /* name of config file */


typedef struct {                         /* Command line options: */
    int       l;                         /* list available designs */
    int       mend;                      /* 1 if -m is given, 2 in 2nd loop */
    int       r;                         /* remove box from input */
    int       tabstop;                   /* tab stop distance */
    char      tabexp;                    /* tab expansion mode (for leading tabs) */
    int       padding[ANZ_SIDES];        /* in spaces or lines resp. */
    design_t *design;                    /* currently used box design */
    int       design_choice_by_user;     /* true if design was chosen by user */
    char     *cld;                       /* commandline design definition, -c */
    long      reqwidth;                  /* requested box width (-s) */
    long      reqheight;                 /* requested box height (-s) */
    char      valign;                    /* text position inside box */
    char      halign;                    /* ( h[lcr]v[tcb] )         */
    char      indentmode;                /* 'b', 't', 'n', or '\0' */
    char      justify;                   /* 'l', 'c', 'r', or '\0' */
    int       killblank;                 /* -1 if not set */
    FILE     *infile;                    /* where we get our input */
    FILE     *outfile;                   /* where we put our output */
} opt_t;

extern opt_t opt;


typedef struct {
    size_t  len;                         /* length of text in characters */
    char   *text;                        /* line content, tabs expanded */
    size_t *tabpos;                      /* tab positions in expanded work strings */
    size_t  tabpos_len;                  /* number of tabs in a line */
} line_t;

#ifndef FILE_LEXER_L
typedef struct {
    line_t *lines;
    size_t anz_lines;                    /* number of entries in input */
    size_t maxline;                      /* length of longest input line */
    size_t indent;                       /* number of leading spaces found */
} input_t;

#define INPUT_INITIALIZER {NULL, 0, 0, LINE_MAX}

extern input_t input;
#endif /*!FILE_LEXER_L*/


#endif /* BOXES_H */

/*EOF*/                                  /* vim: set cindent sw=4 syntax=c: */
